package com.example.foo.weixin.wxpay.config;

import com.example.support.wechat.boot.WechatProperties;
import com.example.foo.weixin.wxpay.sdk.IWXPayDomain;
import com.example.foo.weixin.wxpay.sdk.WXPayConfig;
import com.example.foo.weixin.wxpay.sdk.WXPayConstants;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class IWxPayConfig extends WXPayConfig {

	private final WechatProperties.Wechat wechat;

	public IWxPayConfig(WechatProperties.Wechat wechat) {
		this.wechat = wechat;
	}

    @Override
    public String getAppID() {
        return wechat.getMp().getAppId();
    }

    @Override
    public String getMchID() {
        return wechat.getPay().getMchId();
    }

    @Override
    public String getKey() {
        return wechat.getPay().getKey();
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(wechat.getPay().getCertData());
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }
            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }

}
